<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>LCV Framework: gpio-target.c Quellcode</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Erzeugt von Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Hauptseite</span></a></li>
    <li><a href="classes.html"><span>Datenstrukturen</span></a></li>
    <li class="current"><a href="files.html"><span>Dateien</span></a></li>
  </ul>
</div>
<h1>gpio-target.c</h1><a href="gpio-target_8c.html">gehe zur Dokumentation dieser Datei</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;sys/ioctl.h&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;linux/ioctl.h&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;unistd.h&gt;</span> 
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include "pflags.h"</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="gpio_8h.html" title="Die Schnittstelle zu den GPIO Ports.">gpio.h</a>"</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="gpio-port-config_8h.html" title="Enthält die Geräteadressen der GPIO Ports.">gpio-port-config.h</a>"</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include "<a class="code" href="log_8h.html" title="Ein Werkzeug zur Protokollierung.">log.h</a>"</span>
<a name="l00020"></a>00020 
<a name="l00021"></a><a class="code" href="gpio-target_8c.html#c1091625d45beae7dbadf8b575f5a3b2">00021</a>  <span class="keywordtype">char</span> <a class="code" href="gpio-linux32_8c.html#c1091625d45beae7dbadf8b575f5a3b2" title="Liest den Wert eines Eingabeports.">lcv_gpio_read</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> port)
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023         <span class="keywordtype">int</span> in_port;    
<a name="l00024"></a>00024         <span class="keywordtype">int</span> ret;
<a name="l00025"></a>00025         <span class="keywordtype">char</span> in_read[2]; 
<a name="l00026"></a>00026         <span class="comment">/* Es ist notwendig, jeweils zwei Einträge zu lesen um korrekte Werte zu erhalten, wir wissen nicht warum*/</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028         <span class="keywordflow">if</span> (port &gt; <a class="code" href="gpio-port-config_8h.html#87d7aa3bf12e9fe7185f732138ca1323" title="Anzahl In-Ports.">gpio_in_ports_cnt</a>) {
<a name="l00029"></a>00029                 <span class="keywordflow">return</span> <a class="code" href="lcv-config_8h.html#db1d839e5201fcf44c454f8596cfd9af">ERROR_ILLEGAL_PORT</a>;
<a name="l00030"></a>00030         }       
<a name="l00031"></a>00031         
<a name="l00032"></a>00032         in_port = open(<a class="code" href="gpio-port-config_8h.html#6b55fc7a71bf7f25cda252b9a6756d28" title="Array mit Deviceadressen der In-Ports.">gpio_in</a>[port],O_RDONLY,0);
<a name="l00033"></a>00033                 
<a name="l00034"></a>00034         <span class="keywordflow">if</span> (in_port == -1) {
<a name="l00035"></a>00035                 <span class="keywordflow">return</span> <a class="code" href="lcv-config_8h.html#8fe83ac76edc595f6b98cd4a4127aed5" title="Errors.">ERROR</a>;
<a name="l00036"></a>00036         }
<a name="l00037"></a>00037         
<a name="l00038"></a>00038         ret = ioctl(in_port, SET_FIO_DIR, INPUT);       
<a name="l00039"></a>00039         ret = ioctl(in_port, SET_FIO_INEN, INPUT_ENABLE);
<a name="l00040"></a>00040         <span class="comment">/* Reagiere nicht auf Flanken, sondern auf Level*/</span>
<a name="l00041"></a>00041         ret = ioctl(in_port, SET_FIO_EDGE, LEVEL);
<a name="l00042"></a>00042 
<a name="l00043"></a>00043         read(in_port, in_read,2);
<a name="l00044"></a>00044 
<a name="l00045"></a>00045         <span class="keywordflow">if</span> (in_read[0] == <span class="charliteral">'1'</span>) {
<a name="l00046"></a>00046                 ret = 1;
<a name="l00047"></a>00047         } <span class="keywordflow">else</span> {
<a name="l00048"></a>00048                 ret = 0;
<a name="l00049"></a>00049         }
<a name="l00050"></a>00050         close(in_port);
<a name="l00051"></a>00051         <span class="keywordflow">return</span> ret;
<a name="l00052"></a>00052 }
<a name="l00053"></a>00053 
<a name="l00054"></a><a class="code" href="gpio-target_8c.html#b9f8e9e1180ce0f6c40fc07382807c07">00054</a> <span class="keywordtype">char</span> <a class="code" href="gpio-linux32_8c.html#b9f8e9e1180ce0f6c40fc07382807c07" title="Schreibt den Wert eines Ausgabeports.">lcv_gpio_write</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> port, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> value)
<a name="l00055"></a>00055 {       
<a name="l00056"></a>00056         <span class="keywordtype">int</span> out_port;   
<a name="l00057"></a>00057         <span class="keywordtype">int</span> ret;
<a name="l00058"></a>00058         <span class="keywordtype">char</span>* val;
<a name="l00059"></a>00059         
<a name="l00060"></a>00060         <span class="keywordflow">if</span> (port &gt; <a class="code" href="gpio-port-config_8h.html#e62a1686c442c3939078c191a0db01c7" title="Anzahl Out-Ports.">gpio_out_ports_cnt</a>) {
<a name="l00061"></a>00061                 <span class="keywordflow">return</span> <a class="code" href="lcv-config_8h.html#db1d839e5201fcf44c454f8596cfd9af">ERROR_ILLEGAL_PORT</a>;
<a name="l00062"></a>00062         }       
<a name="l00063"></a>00063 
<a name="l00064"></a>00064         <span class="comment">/* Nur 0 und 1 als Werte zulassen */</span>
<a name="l00065"></a>00065         <span class="keywordflow">switch</span> (value) {
<a name="l00066"></a>00066                 <span class="keywordflow">case</span> 0:
<a name="l00067"></a>00067                         val = <span class="stringliteral">"0"</span>;              
<a name="l00068"></a>00068                         <span class="keywordflow">break</span>;
<a name="l00069"></a>00069                 <span class="keywordflow">case</span> 1:
<a name="l00070"></a>00070                         val = <span class="stringliteral">"1"</span>;
<a name="l00071"></a>00071                         <span class="keywordflow">break</span>;
<a name="l00072"></a>00072                 <span class="keywordflow">default</span>:
<a name="l00073"></a>00073                         <span class="keywordflow">return</span> <a class="code" href="lcv-config_8h.html#a8cbb6e43280c20eb5a8f0b2db94fcc7">ERROR_ILLEGAL_VALUE</a>;
<a name="l00074"></a>00074         }
<a name="l00075"></a>00075                 
<a name="l00076"></a>00076         out_port = open(<a class="code" href="gpio-port-config_8h.html#573dc3deffc37af124f6c56e4d83e7bd" title="Array mit Deviceadressen der Out-Ports.">gpio_out</a>[port], O_RDWR, 0); 
<a name="l00077"></a>00077         
<a name="l00078"></a>00078         <span class="keywordflow">if</span>(out_port &lt; 0) {
<a name="l00079"></a>00079                 <span class="keywordtype">char</span> log_entry[256];
<a name="l00080"></a>00080                 sprintf (log_entry, <span class="stringliteral">"Could not write GPIO Port %u"</span>, port);
<a name="l00081"></a>00081                 <a class="code" href="log_8c.html#8478a914926d15bf375feb130ff51b3e" title="Schreibt einen Warnungs-Eintrag in die Protokoll-Datei.">lcv_log_warning</a>(log_entry, __FUNCTION__);
<a name="l00082"></a>00082                 <span class="keywordflow">return</span> <a class="code" href="lcv-config_8h.html#8fe83ac76edc595f6b98cd4a4127aed5" title="Errors.">ERROR</a>;
<a name="l00083"></a>00083         }
<a name="l00084"></a>00084 
<a name="l00085"></a>00085         <span class="comment">/* Port Eigenschaften setzen */</span> 
<a name="l00086"></a>00086         ret = ioctl(out_port, SET_FIO_DIR, OUTPUT);
<a name="l00087"></a>00087         ret = ioctl(out_port, SET_FIO_INEN, INPUT_ENABLE);
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         write(out_port,val,<span class="keyword">sizeof</span>(val)); 
<a name="l00090"></a>00090         usleep(1000); <span class="comment">/* Zum Sicherstellen das der Port auch wirklich geschrieben wurde */</span>
<a name="l00091"></a>00091         close(out_port);
<a name="l00092"></a>00092         
<a name="l00093"></a>00093         <span class="keywordflow">return</span> <a class="code" href="lcv-config_8h.html#a8cecfc5c5c054d2875c03e77b7be15d" title="Booleans.">TRUE</a>;
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095 
<a name="l00096"></a>00096 
<a name="l00097"></a><a class="code" href="gpio-target_8c.html#fe074e107ea0df9a1e7becc8cd65cc04">00097</a> <span class="keywordtype">void</span> <a class="code" href="gpio-linux32_8c.html#fe074e107ea0df9a1e7becc8cd65cc04" title="Simuliert einen Input an einem GPIO Port.">lcv_gpio_simulate_input</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> port, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> value)
<a name="l00098"></a>00098 {
<a name="l00099"></a>00099         
<a name="l00100"></a>00100 }
<a name="l00101"></a>00101 
<a name="l00102"></a><a class="code" href="gpio-target_8c.html#ea6d99743be79991a2a0665efac78f92">00102</a> <span class="keywordtype">void</span> <a class="code" href="gpio-linux32_8c.html#ea6d99743be79991a2a0665efac78f92" title="Legt eine Funktion als Event-Handler für Schreiboperationen auf GPIO Ports fest...">lcv_gpio_simulate_output</a>(<span class="keywordtype">void</span> (*handler)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> port, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> value))
<a name="l00103"></a>00103 {
<a name="l00104"></a>00104         
<a name="l00105"></a>00105 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Erzeugt am Wed Dec 19 16:38:17 2007 für LCV Framework von&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>
